package com.newx.file.condition;

import com.newx.file.constant.NewxFileConfigConstant;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author yxl
 * @date 2024/7/5 0005 18:09
 */
public class NewxFileCondition implements Condition {

    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        //检查配置文件是否包含newx.file属性
        boolean result = conditionContext.getEnvironment().containsProperty(NewxFileConfigConstant.NEWX_FILE);
        String property = conditionContext.getEnvironment().getProperty(NewxFileConfigConstant.NEWX_FILE);
        return result && Boolean.parseBoolean(property);
    }
}
